package com.cooba.activitys;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.cooba.R;
import com.cooba.bean.RedWalletBean;
import com.lidroid.xutils.BitmapUtils;

public class RedWalletDetailsActivity extends AppCompatActivity {

    private RedWalletBean redwalletbean;
    private TextView red_wallet_close_btn;
    private ImageView red_wallet_ads_iv;
    private TextView red_wallet_ads_detail_tv;
    private ImageView red_wallet_ads_company_icon;
    private TextView red_wallet_msg;
    private TextView red_wallet_money;
    private TextView red_wallet_tip;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.red_wallet_detail);
        redwalletbean = (RedWalletBean) getIntent().getSerializableExtra("redwallet");
        initView();
        initListener();
        setData();
    }

    private void initListener() {
        red_wallet_close_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        red_wallet_ads_detail_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(RedWalletDetailsActivity.this,RedWalletAdActivity.class);
                intent.putExtra("adurl",redwalletbean.getUrl());
                startActivity(intent);
            }
        });
    }

    private void initView() {
        red_wallet_close_btn= (TextView) findViewById(R.id.red_wallet_close_btn);
        red_wallet_ads_iv= (ImageView) findViewById(R.id.red_wallet_ads_iv);
        red_wallet_ads_detail_tv= (TextView) findViewById(R.id.red_wallet_ads_detail_tv);
        red_wallet_ads_company_icon= (ImageView) findViewById(R.id.red_wallet_ads_company_icon);
        red_wallet_msg= (TextView) findViewById(R.id.red_wallet_msg);
        red_wallet_money= (TextView) findViewById(R.id.red_wallet_money);
        red_wallet_tip= (TextView) findViewById(R.id.red_wallet_tip);
    }

    private void setData() {
        BitmapUtils bitmapUtils=new BitmapUtils(this);
        /**
         * 设置默认的图片展现、加载失败的图片展现
         */
        bitmapUtils.configDefaultLoadingImage(R.mipmap.cooba_icon);
        bitmapUtils.configDefaultLoadFailedImage(R.mipmap.cooba_icon);
        bitmapUtils.display(red_wallet_ads_iv, redwalletbean.getPic());
        bitmapUtils.display(red_wallet_ads_company_icon, redwalletbean.getPhoto());
        red_wallet_msg.setText(redwalletbean.getName()+"给你发了一个红包");
        if (!TextUtils.isEmpty(redwalletbean.getDbMoney())){
            red_wallet_money.setText(redwalletbean.getDbMoney()+"元");
        }else {
            red_wallet_money.setText(redwalletbean.getMsg());
        }
    }
}
